﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ServiceMessages.ResponsePOCOs;

namespace Convo
{
    public partial class AddAccountPage : PhoneApplicationPage
    {
        private ConvoClient client;
        public AddAccountPage()
        {
            InitializeComponent();
            client = new ConvoClient("http://127.0.0.1:81/Service1.svc");
        }

        private void addAccountBtn_Click(object sender, RoutedEventArgs e)
        {
            var request = client.registrationRequest(fullnameTxtBox.Text, emailTxtBox.Text, passwordTxtBox.Password);

            client.ExecuteAsync<RegistrationResponse>(request, (response) =>
            {
                bool success = response.Data.Success;
                if (response.StatusCode == HttpStatusCode.OK && success == true)
                {
                    this.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
                }
                else
                {
                    MessageBox.Show("Email address already in use. Please register with a different email.");
                }
            });
        }
    }
}